package mysql

import (
	"gorm.io/gorm"
	"shuqinovelrpc/shuqinovelrpc/shuqinovelrpc"
)

type Story struct {
	gorm.Model
	Name   string `gorm:"type:varchar(30)"`
	Author string `gorm:"type:varchar(30)"`
}

func (s *Story) StoryAdd(db *gorm.DB) error {
	return db.Create(s).Error
}

func (s *Story) UpdateStory(db *gorm.DB) error {
	return db.Debug().Updates(s).Error
}
func StoryList(db *gorm.DB, in *shuqinovelrpc.StoryListRequest) ([]*shuqinovelrpc.StoryList, error) {
	var list []*shuqinovelrpc.StoryList
	db.Debug().Model(&Story{}).Select(
		"id as story_id",
		"name",
		"author",
	).Scopes(Paginate(int(in.Page), int(in.Size))).Find(&list)
	return list, err
}
